package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PAboutVo;
import com.ruoyi.system.domain.bo.PAboutBo;
import com.ruoyi.system.service.IPAboutService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 关于、帮助Controller
 *
 * @author ruoyi
 * @date 2022-07-13
 */
@Validated
@Api(value = "关于、帮助控制器", tags = {"关于、帮助管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/about")
public class PAboutController extends BaseController {

    private final IPAboutService iPAboutService;

    /**
     * 查询关于、帮助列表
     */
    @ApiOperation("查询关于、帮助列表")
    @SaCheckPermission("system:about:list")
    @GetMapping("/list")
    public TableDataInfo<PAboutVo> list(PAboutBo bo, PageQuery pageQuery) {
        return iPAboutService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出关于、帮助列表
     */
    @ApiOperation("导出关于、帮助列表")
    @SaCheckPermission("system:about:export")
    @Log(title = "关于、帮助", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PAboutBo bo, HttpServletResponse response) {
        List<PAboutVo> list = iPAboutService.queryList(bo);
        ExcelUtil.exportExcel(list, "关于、帮助", PAboutVo.class, response);
    }

    /**
     * 获取关于、帮助详细信息
     */
    @ApiOperation("获取关于、帮助详细信息")
    @SaCheckPermission("system:about:query")
    @GetMapping("/{id}")
    public R<PAboutVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPAboutService.queryById(id));
    }

    /**
     * 新增关于、帮助
     */
    @ApiOperation("新增关于、帮助")
    @SaCheckPermission("system:about:add")
    @Log(title = "关于、帮助", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PAboutBo bo) {
        return toAjax(iPAboutService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改关于、帮助
     */
    @ApiOperation("修改关于、帮助")
    @SaCheckPermission("system:about:edit")
    @Log(title = "关于、帮助", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PAboutBo bo) {
        return toAjax(iPAboutService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除关于、帮助
     */
    @ApiOperation("删除关于、帮助")
    @SaCheckPermission("system:about:remove")
    @Log(title = "关于、帮助", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPAboutService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
